Piecewise linear expressions

27 views
Skip to first unread message

Pierre Haessig

unread,
May 24, 2025, 8:47:12 AM (9 days ago) May 24
to MiniZinc
Hello,

I'm new to MiniZinc (I'm more familiar with imperative programming or with JuMP or similar Linear Programming tools) and I'm struggling to model piecewise linear expressions, i.e. using float variables with if/else conditions and then calling HiGHS as MILP solver.

Here is an example code which breaks

var float: x;
var float: y;
constraint -100 <= x /\ x <= 100;
constraint -100 <= y /\ y <= 100;
% decision tree
%var bool: dt = if x>=1 then y=x else y=0 endif;
var bool: dt = (x>=1 -> y=x) /\ (x<1 -> y=0.0);
 
constraint dt;
solve satisfy;

Depending on how I write the dt variable (which inmy mind are identical), I either get:
  • MiniZinc: flattening error: unbounded coefficient in linear expression. Make sure variables involved in non-linear/logical expressions have finite bounds in their definition or via constraints, or

  • MiniZinc: evaluation error: arithmetic operation on infinite value

I don't understand the complaint about unbounded variables, since I specifically added the x,y in [-100, 100] to avoid this error.

Did I make a basic syntax error ?

Thanks for your feedback.

Best,
Pierre

David Lloyd

unread,
May 24, 2025, 4:33:23 PM (9 days ago) May 24
to mini...@googlegroups.com


```

var -100.00..100.00: x;

var -100.00..100.00: y;
constraint -100 <= x /\ x <= 100;
constraint -100 <= y /\ y <= 100;
% decision tree
% var bool: dt = if x>=1 then y=x else y=0 endif;
var bool: dt = (x>=1 -> y=x) /\ (x<1 -> y=0.0);
 
constraint dt;
solve satisfy;

    
output "Result: \(x) \(y) => \(dt).\n";

```


Try that.


I believe that `float`s can be considered by some solvers as somewhat infinite.


Notice that I added the ` -100.00..100:` to the two variables.


DSL

--
You received this message because you are subscribed to the Google Groups "MiniZinc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to minizinc+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/minizinc/4e19dfe5-4b0c-4f65-916e-c8f980e945bcn%40googlegroups.com.

krzysztof....@gmail.com

unread,
May 25, 2025, 12:12:45 PM (8 days ago) May 25
to MiniZinc
It is not a problem with compilation. When you compile your model and run it in gecode with fzn-gecode command you get

x = -99.9999999999999;

y = -4.94065645841246e-324;

----------


The minizinc cannot parse number -4.94065645841246e-324 and complies on this. BTW, JaCoP solver works on this model gives an output 

x = -99.99999999999713;

y = -0.0;

----------


/Kris

Pierre Haessig

unread,
May 27, 2025, 1:08:37 PM (6 days ago) May 27
to MiniZinc
Thanks a lot for your feedback.

Indeed I had made the confusion between "unbounded float variable + bound constraints" versus "bounded float variable".

The two formulations are not equivalent for the Minizinc flattening process (at least when selecting the HiGHS solver, because with Gecode the process doesn't fail).

Pierre
Reply all
Reply to author
Forward
0 new messages